package com.example.controller;

import java.io.IOException;
import java.text.SimpleDateFormat;
import java.util.Calendar;
import java.util.Date;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.scheduling.annotation.Scheduled;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.stereotype.Component;
import com.example.service.impl.AutoCbsServerImpl;
import com.example.service.impl.AutoJobcArdMAServerImpl;

@RestController
@Component
@RequestMapping("AutoCbs")
public class AutoCbsController {

	@Autowired
	public AutoJobcArdMAServerImpl AutoJobcArdServer;
	@Autowired
	public AutoCbsServerImpl AutoCbsServer;

	/**
	 * 管线专业
	 * 
	 * @return
	 * @throws IOException
	 */
	@RequestMapping("test1")
	@ResponseBody
	// @Scheduled(cron = "0 0/2 * * * ?")
	public String dataTrans() throws IOException {
		AutoCbsServer.AnalyzeMTRExcelPI();
		// AutoCbsServer.AnalyzeWeldListExcelPI();
		return "Success";
	}

	
	/**
	 * 结构专业
	 * 
	 * @return
	 * @throws IOException
	 */
	@RequestMapping("AnalyzeMTRExcelST")
	@ResponseBody
//	@Scheduled(cron = "0 0 1 * * ?") // 每天凌晨一点执行一次
	public String AnalyzeMTRExcelST() throws IOException {

		Calendar ca = Calendar.getInstance();// 得到一个Calendar的实例
		ca.setTime(new Date()); // 设置时间为当前时间

		Date lastMonth = ca.getTime(); // 结果
		SimpleDateFormat yyyyMMddDate = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
		String yyyyMMdd = yyyyMMddDate.format(lastMonth);
		System.err.println("时间：" + yyyyMMdd + "执行了读取ST专业MTR");

		AutoCbsServer.AnalyzeMTRExcelST();

		return "Success";
	}
	
	/**
	 * 结构专业
	 * 
	 * @return
	 * @throws IOException
	 */
	@RequestMapping("AnalyzeWeldListExcelST")
	@ResponseBody
//	@Scheduled(cron = "0 0 1 * * ?") // 每天凌晨一点执行一次
	public String AnalyzeWeldListExcelST() throws IOException {
		Calendar ca = Calendar.getInstance();// 得到一个Calendar的实例
		ca.setTime(new Date()); // 设置时间为当前时间

		Date lastMonth = ca.getTime(); // 结果
		SimpleDateFormat yyyyMMddDate = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
		String yyyyMMdd = yyyyMMddDate.format(lastMonth);
		System.err.println("时间：" + yyyyMMdd + "执行了读取ST专业wedlList");

		AutoCbsServer.AnalyzeWeldListExcelST();
		return "Success";
	}

	
	/**
	 * 设备专业
	 * 
	 * @return
	 * @throws IOException
	 */
	@RequestMapping("test3")
	@ResponseBody
	// @Scheduled(cron = "0 0/2 * * * ?")
	public String dataTrans3() throws IOException {
		AutoCbsServer.AnalyzeMTRExcelMA(); // 解析物料追踪表 设备专业
//		AutoCbsServer.AnalyzeWeldListExcelMA();//解析焊口信息 设备专业
		return "Success";
	}

	/**
	 * 管线试压包
	 * 
	 * @return
	 * @throws IOException
	 */
	@RequestMapping("test4")
	@ResponseBody
	public String dataTrans4() throws IOException {
		AutoCbsServer.AnalyzePressurePackagePI();
		return "Success";
	}

	@RequestMapping("test5")
	@ResponseBody
	public String dataTrans5() throws IOException {
		AutoCbsServer.test();
		return "Success";
	}



	@RequestMapping("test6")
	@ResponseBody
	public String dataTrans6() throws IOException{
		AutoCbsServer.AnalyzeMTRExcelAR();
		return "Success";
	}
}
